package dat255.calendarclock.controller.event.activity;

import java.util.GregorianCalendar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.DatePicker;
import dat255.calendarclock.R;
import dat255.calendarclock.model.event.EventHandler;

/**
 * The activity where the current day is selected
 * 
 * @author Marcus Hultman & Gabriel Andersson
 */
public class DayPickerActivity extends Activity {

	private static DatePicker datePicker;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.daypicker_layout);
		datePicker = (DatePicker) findViewById(R.id.dayPicker_datePicker);
		GregorianCalendar date = EventHandler.getInstance().getSelectedDay();
		datePicker.updateDate(date.get(GregorianCalendar.YEAR),
				date.get(GregorianCalendar.MONTH),
				date.get(GregorianCalendar.DATE));
	}

	@Override
	protected void onResume() {
		super.onResume();
		GregorianCalendar date = EventHandler.getInstance().getSelectedDay();
		datePicker.updateDate(date.get(GregorianCalendar.YEAR),
				date.get(GregorianCalendar.MONTH),
				date.get(GregorianCalendar.DATE));
	}

	public void doneButtonClicked(View view) {
		DatePicker datePicker = (DatePicker) findViewById(R.id.dayPicker_datePicker);
		EventHandler.getInstance().setSelectedDay(
				new GregorianCalendar(datePicker.getYear(), datePicker
						.getMonth(), datePicker.getDayOfMonth()));
		this.finish();
	}
}
